<template>
  <div>
    <a-form :model="form" layout="vertical" @submit-success="submit">
      <a-card :bordered="false">
        <a-form-item name="dictName" :label="t['分类名']">
          <a-input v-model="form.dictName"></a-input>
        </a-form-item>
        <a-form-item name="dictValue" :label="t['分类值']">
          <a-input v-model="form.dictValue"></a-input>
        </a-form-item>
        <a-form-item name="dictValue" :label="t['排序']">
          <a-input-number v-model="form.dictSort"></a-input-number>
        </a-form-item>
        <a-form-item name="dictType" disabled :label="t['字典类型']">
          <a-input v-model="form.dictType"></a-input>
        </a-form-item>
        <a-button :loading="loading" long type="primary" html-type="submit">
          {{ t["确定"] }}
        </a-button>
      </a-card>
    </a-form>
  </div>
</template>

<script setup lang="ts">
import { addDictData, updateDictData } from "@/api/service/dict/data/dict.data";

import { list } from "../data/curd";
import { form, showForm } from "../data/form";

const t = translate("公共模块");

const loading = ref(false);
const submit = async () => {
  loading.value = true;
  if (!form.value.dictId) {
    await addDictData(form.value);
  } else {
    await updateDictData(form.value);
  }
  loading.value = false;
  list();
  showForm.value = false;
};
</script>

<style lang="scss" scoped></style>
